﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MolyMart
{
    public class Collector
    {
        readonly DBAdapter adapter = new DBAdapter();
        private readonly BlockingCollection<ServerValuesItem> _valuesQueue;

        public Collector(BlockingCollection<ServerValuesItem> valuesQueue)
        {
            _valuesQueue = valuesQueue;
        }

        public void Start()
        {
            adapter.CreateDb();
            adapter.CreateTable();

            while (true)
            {
                var item = _valuesQueue.Take();
                adapter.InsertItem(item);
                if (adapter.ItemsCount >= 1)
                {
                    adapter.CommitItems();
                }
                Thread.Sleep(100);
            }
        }
    }
}
